﻿#include "../lv_Agriculture.h"

lv_obj_t* lv_WIFIConnect_Srceen;
lv_obj_t* WIFIConnect;
static void lv_WIFIConnect_Content(lv_obj_t* parent);
void lv_WIFI_Connect(lv_obj_t* parent, const char* WIFIName);
void lv_WIFIConnect_Page(void)
{
    lv_WIFIConnect_Srceen = lv_obj_create(NULL);
    lv_obj_add_style(lv_WIFIConnect_Srceen, &lv_Clean_Style, LV_STATE_DEFAULT);
    lv_obj_clear_flag(lv_WIFIConnect_Srceen, LV_OBJ_FLAG_SCROLLABLE);
    lv_obj_set_size(lv_WIFIConnect_Srceen, 320, 240);

    lv_Top_StateBar(lv_WIFIConnect_Srceen);  //顶部状态栏
    lv_WIFIConnect_Content(lv_WIFIConnect_Srceen);
    
}

static void lv_WIFIConnect_Content(lv_obj_t* parent)
{
    lv_obj_t* WIFIConnect_Content = lv_obj_create(parent);
    lv_obj_add_style(WIFIConnect_Content, &lv_Clean_Style, LV_STATE_DEFAULT);
    lv_obj_set_align(WIFIConnect_Content, LV_ALIGN_BOTTOM_MID);
    lv_obj_set_size(WIFIConnect_Content, lv_pct(100), lv_pct(85));

    lv_WIFI_Connect(lv_layer_top(), "123");
    lv_obj_set_style_bg_opa(lv_layer_top(), LV_OPA_50, 0);
    lv_obj_set_style_bg_color(lv_layer_top(), lv_palette_main(LV_PALETTE_GREY), 0);
}

lv_group_t* wifi_con_group;

void lv_WIFI_Connect(lv_obj_t* parent,const char *WIFIName)
{
    WIFIConnect = lv_obj_create(parent);
    lv_obj_set_align(WIFIConnect, LV_ALIGN_CENTER);
    lv_obj_set_flex_flow(WIFIConnect, LV_FLEX_FLOW_COLUMN);
    lv_obj_clear_flag(WIFIConnect, LV_OBJ_FLAG_SCROLLABLE);
    lv_obj_set_flex_align(WIFIConnect, LV_FLEX_ALIGN_SPACE_EVENLY, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
    lv_obj_set_size(WIFIConnect, lv_pct(95), lv_pct(70));
    lv_obj_t* WIFI_label = lv_label_create(WIFIConnect);
    lv_label_set_text(WIFI_label, WIFIName);
    
    wifi_con_group = lv_group_create();
    lv_indev_set_group(indev_keypad,wifi_con_group);

    lv_obj_t* WIFI_Input = lv_textarea_create(WIFIConnect);
    lv_textarea_set_one_line(WIFI_Input, true);

    lv_obj_t* kb = lv_keyboard_create(lv_layer_top());
    lv_obj_add_flag(kb,LV_OBJ_FLAG_HIDDEN);
    lv_obj_add_event_cb(WIFI_Input, KeyBorad_Callback, LV_EVENT_ALL, kb);
    
    lv_obj_t* BOTTOM = lv_obj_create(WIFIConnect);
    lv_obj_add_style(BOTTOM, &lv_Clean_Style, LV_STATE_DEFAULT);
    lv_obj_set_size(BOTTOM, lv_pct(100), LV_SIZE_CONTENT);
    lv_obj_set_flex_flow(BOTTOM, LV_FLEX_FLOW_ROW);
    lv_obj_set_flex_align(BOTTOM, LV_FLEX_ALIGN_SPACE_BETWEEN, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);

    lv_obj_t* Connect_Btn = lv_btn_create(BOTTOM);
    lv_obj_t* Connect_label= lv_label_create(Connect_Btn);
    lv_label_set_text(Connect_label, "Connect");
    lv_obj_add_event_cb(Connect_Btn, WIFI_ConnectBtn_Callback, LV_EVENT_PRESSED, NULL);

    lv_obj_t* Exit_Btn = lv_btn_create(BOTTOM);
    lv_obj_t* Exit_label = lv_label_create(Exit_Btn);
    lv_label_set_text(Exit_label, "Exit");
    lv_obj_add_event_cb(Exit_Btn, WIFI_ExitBtn_Callback, LV_EVENT_PRESSED, NULL);

    lv_group_add_obj(wifi_con_group,WIFI_Input);
    lv_group_add_obj(wifi_con_group,Connect_Btn);
    lv_group_add_obj(wifi_con_group,Exit_Btn);
    lv_group_add_obj(wifi_con_group,kb);
}
